package com.example.com.common.view.dialog;


import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.example.com.common.R;
import com.example.com.common.view.NumberProgressBar;


public class NumbProgressDialog extends BaseDialog {
    View.OnClickListener leftBtnListener, rightBtnListener;
    private NumberProgressBar pbProgress;
    String leftBtnText, rightBtnText;
    String title;
    TextView mTextView;
    private int mCurrentProgress;
    int mMaxProgress;
    int gravity = Gravity.CENTER_VERTICAL;

    /**
     * @param title       下载描述信息
     * @param maxProgress 最大进度
     */
    public NumbProgressDialog(Context context, String title, int maxProgress) {
        super(context, R.style.translucentDialog);
        this.title = title;
        mMaxProgress= maxProgress;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_numb_progress);
        mTextView = (TextView) findViewById(R.id.tv_dialog_title);
        setTitle(title);
        pbProgress = (NumberProgressBar) findViewById(R.id.pbProgress);
        pbProgress.setMax(mMaxProgress);
    }

    public int getCurrentProgress() {
        return mCurrentProgress;
    }

    public void setCurrentProgress(int currentProgress) {
        mCurrentProgress = currentProgress;
        if (pbProgress != null) {
            pbProgress.setProgress(mCurrentProgress);
        }
    }

    public int getMaxProgress() {
        return mMaxProgress;
    }

    public void setMaxProgress(int maxProgress) {
        mMaxProgress = maxProgress;
        if (pbProgress != null) {
            pbProgress.setMax(mMaxProgress);
        }
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
        if (!TextUtils.isEmpty(title)) {
            mTextView.setVisibility(View.VISIBLE);
            mTextView.setText(title);
        } else {
            mTextView.setVisibility(View.GONE);
            mTextView.setVisibility(View.GONE);
        }
    }

    public void setGravity(int gravity) {
        this.gravity = gravity;
    }

    private boolean canceledOnTouchOutside = true;

    @Override
    public void setCanceledOnTouchOutside(boolean cancel) {
        this.canceledOnTouchOutside = cancel;
    }
}
